home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LightWavin' Magazine 3
/
LightWavin' Magazine, Issue 3 (LightWavin' Multimedia)(1997).iso
/
alphac~1
/
intel
/
alphclip.c
next >
Wrap
C/C++ Source or Header
|
1997-03-25
|
7KB
|
353 lines
/*
* ALPHCLIP.C -- Layout Plugin Image Filter
*
* This plugin will clip out various portions of the alpha
* channel of an image.
*
* Version 1.00, by Brenden Mecleary
* last revision 3/23/97
*
*
*/
#include <splug.h>
#include <moni.h>
#include <lwran.h>
#include <lwpanel.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* These globals make adding controls easier. */
static LWPanControlDesc desc;
static LWValue ival={LWT_INTEGER},ivecval={LWT_VINT},
fval={LWT_FLOAT},fvecval={LWT_VFLOAT},sval={LWT_STRING};
/* This structure will hold all the necessary information for the clipping. */
typedef struct AACLIPINFO_TAG{
int nRfill, nGfill, nBfill, nClipThreshold, nSideFlag;
} AACLIPINFO;
/* The damn thing doesn't just accept int values, so I had to make
* my own structure to hold settings for the panel. */
typedef struct MYPANINFO_TAG{
int x, y;
} MYPANINFO;
/*
* FUNCTIONS
*/
XCALL_(static LWInstance)
ACCreate (LWError *err)
{
AACLIPINFO *aaci;
XCALL_INIT;
aaci = calloc(sizeof(struct AACLIPINFO_TAG),1);
aaci->nClipThreshold = 255;
aaci->nSideFlag = 0;
aaci->nRfill = 0;
aaci->nGfill = 255;
aaci->nBfill = 0;
return ((LWInstance) aaci);
}
XCALL_(void)
ACDestroy (LWInstance inst)
{
XCALL_INIT;
if (inst)
free(inst);
}
XCALL_(static LWError)
ACCopy (
LWInstance from,
LWInstance to)
{
AACLIPINFO *old, *new;
old = (AACLIPINFO *) from;
new = (AACLIPINFO *) to;
*new = *old;
return (NULL);
}
XCALL_(static LWError)
ACLoad (
LWInstance inst,
const LWLoadState *ls)
{
AACLIPINFO *aaci;
char line[80];
XCALL_INIT;
aaci = (AACLIPINFO *) inst;
(*ls->read)(ls->readData,line,80);
sscanf(line,"%i %i %i %i %i",
&aaci->nRfill,
&aaci->nGfill,
&aaci->nBfill,
&aaci->nClipThreshold,
&aaci->nSideFlag);
return (NULL);
}
XCALL_(static LWError)
ACSave (
LWInstance inst,
const LWSaveState *ss)
{
AACLIPINFO *aaci;
char line[80];
XCALL_INIT;
aaci = (AACLIPINFO *) inst;
sprintf(line,"%i %i %i %i %i",
aaci->nRfill,
aaci->nGfill,
aaci->nBfill,
aaci->nClipThreshold,
aaci->nSideFlag);
(*ss->write)(ss->writeData,line,80);
return (NULL);
}
/*
* PROCESSING
*/
XCALL_(static void)
ACClipProcess (
LWInstance inst,
const FilterAccess *fa)
{
AACLIPINFO *aaci;
Monitor *mon;
BufferValue out[4], *r, *g, *b, *a;
int i, j;
aaci = (AACLIPINFO *) inst;
mon = fa->monitor;
/*
* Scan through the lines in the image and get image buffer
* line pointers for the RGB and alpha buffers of the original
* image.
*/
MON_INIT (mon, fa->height);
for (i = 0; i < fa->height; i++) {
r = (*fa->bufLine) (LWBUF_RED, i);
g = (*fa->bufLine) (LWBUF_GREEN, i);
b = (*fa->bufLine) (LWBUF_BLUE, i);
a = (*fa->bufLine) (LWBUF_ALPHA, i);
/* Loops through each pixel in the current line */
for (j = 0; j < fa->width; j++) {
/*
* For each pixel in the current line, key off the alpha
* channel to determine if the pixel should simply be copied,
* or replaced with the background "fill" color.
*/
switch(aaci->nSideFlag)
{
case 1:
if(a[j] > aaci->nClipThreshold)
{
out[0] = aaci->nRfill;
out[1] = aaci->nGfill;
out[2] = aaci->nBfill;
out[3] = a[j];
}
else
{
out[0] = r[j];
out[1] = g[j];
out[2] = b[j];
out[3] = a[j];
}
break;
default:
if(a[j] < aaci->nClipThreshold)
{
out[0] = aaci->nRfill;
out[1] = aaci->nGfill;
out[2] = aaci->nBfill;
out[3] = a[j];
}
else
{
out[0] = r[j];
out[1] = g[j];
out[2] = b[j];
out[3] = a[j];
}
break;
}
(*fa->setRGB) (j, i, out);
(*fa->setAlpha) (j, i, out[3]);
}
/* Step the monitor on every 10th go...I think. */
if ((i % 10) == 0)
{
if (MON_INCR (mon, 10))
return;
}
}
MON_DONE (mon);
}
/*
* FLAGS
*/
XCALL_(static unsigned int)
ACClipFlags (
LWInstance inst)
{
return (0);
}
/*
* ACTIVATION
*/
XCALL_(int)
ACActivate (
long version,
GlobalFunc *global,
ImageFilterHandler *local,
void *serverData)
{
XCALL_INIT;
if (version != 1)
return (AFUNC_BADVERSION);
local->create = ACCreate;
local->destroy = ACDestroy;
local->load = ACLoad;
local->save = ACSave;
local->copy = ACCopy;
local->process = ACClipProcess;
local->flags = ACClipFlags;
return (AFUNC_OK);
}
/*
* INTERFACE
*/
XCALL_(static int)
ACInterface (
long version,
GlobalFunc *global,
AACLIPINFO *inst,
void *serverData)
{
LWPanelFuncs *panl;
LWPanelID panID;
LWControl *info;
MessageFuncs *message;
MYPANINFO mypi;
char *cPopupChoices[][17] = {"MORE transparent", "LESS transparent"};
/* Set up the panel structure values*/
mypi.x = 160;
mypi.y = 120;
/* Lightwave-specific shit. */
XCALL_INIT;
message = (*global) ("Info Messages", GFUSE_TRANSIENT);
if (!message )
return AFUNC_BADGLOBAL;
panl = (*global) (PANEL_SERVICES_NAME, GFUSE_TRANSIENT);
if(!panl)
{
(*message->error)("Unable to activate global "PANEL_SERVICES_NAME, " please add plugin lwpanels.p" );
return AFUNC_BADGLOBAL;
}
/* Setting up the panel. */
panID = PAN_CREATE(panl,"AlphaClip Version 1.00 - ⌐ 1997, Brenden Mecleary");
panl->set(panID, PAN_X, &mypi.x);
panl->set(panID, PAN_Y, &mypi.y);
/* Adding controls onto the panel. */
RGB_CTL(panl, panID, "Fill color:");
SLIDER_CTL(panl, panID, "Threshold:", 200, 0, 255);
POPUP_CTL(panl, panID, "Clip mode:", cPopupChoices[0]);
/* Load instance data into the controls. */
info = panl->nextControl(panID, NULL);
SET_IVEC(info, inst->nRfill, inst->nGfill, inst->nBfill);
info = panl->nextControl(panID, info);
SET_INT(info, inst->nClipThreshold);
info = panl->nextControl(panID, info);
if(inst->nSideFlag == 1)
SET_INT(info, 1);
else
SET_INT(info, 0);
/* Draw the panel. */
panl->open(panID, PANF_BLOCKING);
/* Save the panel information. */
info = panl->nextControl(panID, NULL);
GET_IVEC(info, inst->nRfill, inst->nGfill, inst->nBfill);
info = panl->nextControl(panID, info);
GET_INT(info, inst->nClipThreshold);
info = panl->nextControl(panID, info);
GET_INT(info, inst->nSideFlag);
/* Destroying the panel. */
PAN_KILL(panl,panID);
return (AFUNC_OK);
}
/*
* Globals used to identify this plugin to Lightwave.
*/
ServerRecord ServerDesc[] = {
{ "ImageFilterHandler", "Bman's_AlphaClip", ACActivate },
{ "ImageFilterInterface", "Bman's_AlphaClip", ACInterface },
{ NULL }
};